<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: pink;
            transition: all 1s;
        }
        
        .change {
            width: 200px;
            height: 200px;
            background-color: purple;
            margin-top: 100px;
            font-size: 25px;
            color: #cccccc;
        }
    </style>
</head>

<body>
    <div>文本</div>
    <script>
        // 1.使用 element.style 获得修改元素样式
        var test = document.querySelector('div');
        test.onclick = function() {
            // this.style.backgroundColor = 'purple'
            // this.className = 'change'
            // 2.可以通过 修改元素的className 更改元素的样式 适合于样式较多或者功能复杂的情况
            // 3.如果想要保留原先的类名
            this.className = 'first change'
        }
    </script>
</body>

</html>